<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//base
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'base.class.php');

//base owner
if( SYS_RT_LANG == 'en_us' ) {
	$base_owner = 1;
} elseif( SYS_RT_LANG == 'zh_tw' ) {
	$base_owner = 2;
} elseif( SYS_RT_LANG == 'zh_cn' ) {
	$base_owner = 3;
} else {
	$base_owner = 1;
}

//user
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'user.class.php');
$userObj = new UserBase();

//filecache
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.filecache.class.php');
$filecacheObj = new CoreFileCache();
$filecacheObj->setKP('m');

//setting
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.setting.class.php');
$settingObj = new CoreSettingBase();
$SETTINGS = $settingObj->cache('getSettings');

//inject
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.injection.class.php');
$injectObj = new CoreInjection();

//breadcrumb
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.breadcrumb.class.php');
$bcObj = new CoreBreadcrumb();
$bcObj->init();

//messagestack
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.messagestack.class.php');
//create object after session started
//$messagestackObj = new CoreMessageStack();

//viewhistory
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.viewhistory.class.php');

//filter
include_once(CONFIG_PATH . CONFIG_DIR_FUNCTIONS . 'filter.function.php');

//templates
include_once(CONFIG_PATH . CONFIG_DIR_FUNCTIONS . 'tpl.function.php');
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'template.base.class.php');
$tpl = new Template;

//resource/attachment
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.resource.class.php');
$resObj = new CoreResourceBase();

//frontend
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'frontend.class.php');

//
//cache limit
if( strstr(SYS_RT_REQUEST_URI, 'admin') === false ) {
	//session_cache_limiter('public');
	//session_cache_limiter('private');
	//
	header('Content-Type: text/html;charset=UTF-8');
	header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
	header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 86400) . ' GMT');
}

//set the cookie domain
$request_ssl = 'NONSSL';
$cookie_domain = (($request_ssl == 'NONSSL') ? CONFIG_COOKIE_DOMAIN_HTTP : CONFIG_COOKIE_DOMAIN_HTTPS);
$cookie_path = (($request_ssl == 'NONSSL') ? CONFIG_COOKIE_PATH_HTTP : CONFIG_COOKIE_PATH_HTTPS);

//
//start the session
//session
//include_once(CONFIG_PATH . CONFIG_DIR_FUNCTIONS . 'session.function.php');
include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'core.session.class.php');
$sessionObj = new CoreSessionBase();
$sessionObj->start();

//set SID once, even if empty
$SID = (defined('SID') ? SID : '');

//user
if( isset($_SESSION['suser']) && is_object($_SESSION['suser']) ) {
	//do nothing
	$_SESSION['suser']->doConsistent();
	//
	$userObj->doLoginUpdateTime();
} else {
	$_SESSION['suser'] = new UserSession();
}

//create object after session started
$messagestackObj = new CoreMessageStack();
//
?>